<template>
  <a-form ref="deptFormRef" :model="deptModel" :rules="deptFormRule" v-bind="layout">
    <a-form-item name="parentDeptName" :label="t('org.dept.parentDepartment')">
      <a-input v-model:value="deptModel.parentDeptName" :disabled="true" />
    </a-form-item>
    <a-form-item name="deptCode" :label="t('org.dept.departmentCode')">
      <a-input v-model:value="deptModel.deptCode" :placeholder="t('org.dept.formPlhDeptCode')" />
    </a-form-item>
    <a-form-item name="deptName" :label="t('org.dept.departmentName')">
      <a-input v-model:value="deptModel.deptName" :placeholder="t('org.dept.formPlhDeptName')" />
    </a-form-item>
    <a-form-item name="enabledTime" :label="t('org.dept.startTime')">
      <a-date-picker
        style="width: 100%"
        v-model:value="deptModel.enabledTime"
        valueFormat="YYYY-MM-DD"
        :placeholder="t('org.dept.formPlhStartTime')"
      />
    </a-form-item>
    <a-form-item name="deptFullName" :label="t('org.dept.fullName')">
      <a-input v-model:value="deptModel.deptFullName" />
    </a-form-item>

    <a-form-item name="deptType" :label="t('org.dept.departmentType')">
      <qc-dictionary-select codeItemId="ORG_DEPT_TYPE" v-model:value="deptModel.deptType"> </qc-dictionary-select>
    </a-form-item>
    <a-form-item name="sortNo" :label="t('org.dept.sort')">
      <a-input v-model:value="deptModel.sortNo" />
    </a-form-item>
  </a-form>
</template>
<script lang="ts">
import { useI18n } from 'vue-i18n'
import { defineComponent, ref } from 'vue'
import { deptFormRule } from '../interface'
import deptApi from '/@/api/org/dept'
import { useModelForm } from '/@/kit/model-kit'
export default defineComponent({
  props: {
    deptId: String, //部门id 可以不存在 不存在即为新增页面
    parentDeptId: String, //新增操作时会带来父部门id
  },
  setup(props) {
    const { t } = useI18n()

    const deptFormRef = ref()
    const deptModel = ref({
      deptAvatar: null,
      parentId: null,
      parentDeptName: null,
    })
    const layout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 14 },
    }

    const { save } = useModelForm(deptFormRef, deptModel, props.deptId, deptApi, {
      newModelParam: { parentDeptId: props.parentDeptId },
    })

    //提交方法
    const onSubmit = () => save()
    return {
      t,
      deptFormRef,
      deptModel,
      deptFormRule,
      layout,
      onSubmit,
    }
  },
})
</script>

